# class Person:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age

#     def describe(self):
#         return f"{self.name} is {self.age} years old."

#     def birthday(self):
#         self.age += 1
#         return f"Happy {self.age}th birthday, {self.name}!"
import random
class Orange:
    # orange_img是图片路径；image是标签
    def __init__(self, orange_img, orange_explosion,imagesize,xx,yy,actual_width,actual_height,image):
        self.orange_img = orange_img
        self.orange_explosion = orange_explosion
        self.noworange = orange_img    
        self.imagesize = imagesize                
        self.xx = xx
        self.yy = yy
        self.actual_width = actual_width
        self.actual_height = actual_height
        self.explosionflag = False
        self.image = image
        self.flynum = 0
        self.swapimage = 'a'

    def describe(self):
        x1 = self.xx
        print(f"{self.orange_img} :{x1} is {self.orange_explosion} years old.") 


    def addyy(self,gamespeed):
        self.yy = self.yy+gamespeed*2
        if self.flynum<3:
            self.flynum = self.flynum +1
        else:
            self.flynum = 0
            # 停止闪烁
            # if self.swapimage ==  'a'  :
            #     self.noworange = self.orange_explosion
            #     self.swapimage = 'b'
            # else:
            #     self.noworange = self.orange_img
            #     self.swapimage = 'a'

    def randomxx(self):
        self.xx = random.randint(1, 800)


    def checkhit(self,frame):
        self.yy = self.yy

    def checkoranger(self,frame,results):
        global x
        global y
        global orange_img
        self.explosionflag = False 
        i = 0
        # 检查是否检测到姿态
        if results.pose_landmarks:
            # 遍历所有关键点
            for landmark in results.pose_landmarks.landmark:
                if landmark.visibility<0.8: #如果此点不可见，则不算
                    i = i + 1
                    continue
                #只考虑手和脚发挥作用（15-22，27-32），其它的节点不管
                if (i>14 and i < 23) or (i>126 and i < 33):
                    i = i + 1
                else:
                    i = i + 1
                    continue

                # 将归一化坐标转换为像素坐标
                x_pixel = int(landmark.x * self.actual_width)
                y_pixel = int(landmark.y * self.actual_height)
                # print(x,y,x_pixel,y_pixel)
                # 判断关键点是否在定义的区域内
                if self.xx <= x_pixel <= self.xx+self.imagesize and self.yy <= y_pixel <= self.yy+self.imagesize:
                    # print(f'关键点 {landmark.name} 落在区域内: (x: {x_pixel}, y: {y_pixel})')
                    print(self.image)
                    # self.noworange = self.orange_explosion 
                    self.explosionflag = True
                    # explose_floatimae()
                    break
                else:
                    # print('orange_img0')
                    self.noworange = self.orange_img

# obj = Orange("aaa","bbb",1,1,1,1,1)
# obj.describe()